#include "stdafx.h"
#include "msado15_tlh.h"
#include <locale.h>

void WINAPI _com_issue_error(HRESULT hr){
//void _com_issue_error(HRESULT hr) throw(_com_error) {
#if __EXCEPTIONS
    throw _com_error(hr);
#else
    /* This is designed to use exceptions. If exceptions are disabled, there is not much we can do here. */
    __debugbreak();
#endif
}
void WINAPI _com_raise_error(HRESULT hr, IErrorInfo * perrinfo)
{


	throw _com_error(hr, perrinfo, false);
}

void __stdcall _com_issue_errorex(HRESULT hr, IUnknown * pob, REFIID id)
{

	_com_raise_error(hr, NULL);
}
namespace _com_util
{
BSTR __stdcall ConvertStringToBSTR(const char* pSrc) throw(_com_error)
{
	if(pSrc==NULL)return NULL;
	int nLen=lstrlenA(pSrc);
	int nblen=nLen;
	LPWSTR pbstr=(LPWSTR)::operator new((nblen+1)*sizeof(wchar_t));
	int nr=MultiByteToWideChar(CP_ACP,0,
		pSrc,nLen,
		pbstr,nblen);
	if(nr<0)nr=0;
	BSTR rstr=::SysAllocStringLen(pbstr,nr);
	::operator delete(pbstr);
	return rstr;
}
char* __stdcall ConvertBSTRToString(BSTR pSrc) throw(_com_error)
{
	if(pSrc==NULL)return NULL;
	int nLen=::wcslen(pSrc);
	int nmlen=nLen*2+1;
	LPSTR pmstr=(LPSTR)new char[nmlen];
	int newlen=WideCharToMultiByte(CP_ACP,0,pSrc,nLen,pmstr,nmlen,0,0);
	if(newlen<0)newlen=0;
	pmstr[newlen]='\0';
	return pmstr;
}
}
